package com.kyhd.audio.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.kyhd.audio.dao.NovelRepository;
import com.kyhd.audio.dao.model.Novel;

@Service
public class NovelService {

	@Autowired
	NovelRepository novelRepository;
	
	public Novel update(Novel novel) {
		return this.novelRepository.save(novel);
	}

	public Novel updateAudio(Novel novel) {
		novel.setAudio(1);
		return this.update(novel);
	}
	
	public List<Novel> getNovelIdsByNum(int num){
		List<Novel> novels = Lists.newArrayList();
		if(num>0) {
			novels = this.novelRepository.getNovelIdsByNum(num);
		}
		return novels;
	}
	
	public List<String> getByNovelId(String novelId){
		List<String> novels = Lists.newArrayList();
		if(novelId!=null) {
			novels = this.novelRepository.getByNovelId(novelId);
		}
		return novels;
	}
	
	public Novel getByContentId(String contentId) {
		Novel novel = null;
		if(contentId!=null) {
			novel = this.novelRepository.getByContentId(contentId);
		}
		return novel;
	}
	
	public Novel getByNovelIdAndContentId(String novelId, String contentId) {
		Novel novel = new Novel();
		if(novelId!=null&&contentId!=null) {
			novel = this.novelRepository.getByNovelIdAndContentId(novelId, contentId);
		}
		return novel;
	}
	
	
	
}
